import echarts from 'echarts';

function getVirtulData (year) {
    year = year || '2018';
    const date = +echarts.number.parseDate(year + '-01-01');
    const end = +echarts.number.parseDate((+year + 1) + '-01-01');
    const dayTime = 3600 * 24 * 1000;
    const data = [];
    for (let time = date; time < end; time += dayTime) {
        data.push([
            echarts.format.formatTime('yyyy-MM-dd', time),
            (Math.random() > 0.9) ? Math.floor(Math.random() * 20) : 0
        ]);
    }
    return data;
}

export const calendarSolveOption = {
    tooltip: {
        position: 'top',
        formatter (params) {
            const formatDate = params.data[0].replace('-', '年').replace('-', '月') + '日';
            return `${formatDate}<br>解决${params.data[1]}次报障`
        }
    },

    visualMap: [{
        show: false,
        min: 0,
        max: 20,
        inRange: {
            color: ['#19be6b'],
            opacity: [0, 1]
        },
        controller: {
            inRange: {
                opacity: [0.3, 0.6]
            },
            outOfRange: {
                color: '#ccc'
            }
        },
        calculable: true,
        seriesIndex: [0],
    }],

    calendar:
        {
            orient: 'horizontal',
            yearLabel: {
                show: false
            },
            dayLabel: {
                firstDay: 1,
                nameMap: ['周日', '周一', '周二', '周三', '周四', '周五', '周六']
            },
            monthLabel: {
                nameMap: 'cn',
                margin: 10
            },
            cellSize: 'auto',
            top: 50,
            left: 55,
            right: 15,
            bottom: 40,
            range: ['2017-12-22', '2018-03-23']
        },

    series: [{
        type: 'heatmap',
        coordinateSystem: 'calendar',
        data: getVirtulData(2018)
    }]
};
